$(function(){
    
    $("#btnMake").bind("click", makeTransfer);
   
});

function makeTransfer()
{
    var ph1 = $("#inpPhone1").val();
    if(isPhoneNumber(ph1) == false) return;

    var ph2 = $("#inpPhone2").val();
    if(isPhoneNumber(ph2) == false) return;
    

    var sum = $("#inpSum").val();
    if(sum.length == 0)
    {
        alert(ss['err-empty-sum']);
        return;
    }
    
    sendTransfer(ph1, ph2, sum);
}


function acceptDigits(objtextbox)
{
    var exp = /[^\d]/g;
    objtextbox.value = objtextbox.value.replace(exp, '');
}

function isPhoneNumber(s) 
{
    // Check for correct phone number
    rePhoneNumber = new RegExp(/^7\d{10}$/);
    if (!rePhoneNumber.test(s))
    {
        alert(ss['err-phone-num']);
        return false;
    }
    return true;
}

function sendTransfer(phone1, phone2, sum)
{
    $.ajax({
        url: "p_ajax.php?act=add&lang="+lang+"&phone1="+phone1+"&phone2="+phone2+"&sum="+sum,
        dataType: 'json',
        success: function(data)
        {
            alert(data.MSG);
            //alert(var_dump(data));
            if(data.STATE == "OK")
            {
                $("#btnGive").show();
            }
            else if(data.STATE == "ALERT")
            {
                $("#btnGive").hide();
            }
            //alert(data);
        }
    });
    // alert("Hi!");
}
